package com.itheima.controller.backend.security.order;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemServcice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @Autowired
    CheckItemServcice checkItemServcice;

    @PostMapping("/add")
    public Result addCheckItem(@RequestBody CheckItem  checkItem) {


        checkItemServcice.addCheckItem(checkItem);

        return new Result(true,"添加成功");
    }

    @GetMapping("/delete")
    public Result deleteCheckItem(@RequestParam Integer id) {

        checkItemServcice.deleteCheckItem(id);

        return new Result(true,"删除成功");
    }

    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer checkgroupId) {

       List<Integer> ids =checkItemServcice.findCheckItemIdsByCheckGroupId(checkgroupId);

        return new Result(true,"查询成功",ids);

    }

    @PostMapping("/edit")
    public Result editCheckItem(@RequestBody CheckItem checkItem) {

        checkItemServcice.editCheckItem(checkItem);

        return new Result(true,"修改成功");
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {

         List<CheckItem> checkItemList = checkItemServcice.findPage(queryPageBean);
         Long total = checkItemServcice.findCount()  ;
         return new PageResult(total, checkItemList);
    }

    @GetMapping("/findAll")
    public Result findAll() {
      List<CheckItem> checkItemList = checkItemServcice.findAll();
      return new Result(true,"查询成功",checkItemList);
    }


    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        CheckItem checkItem = checkItemServcice.findById(id);
        return new Result(true,"查询成功",checkItem);
    }




}
